import { FileStat, FileType } from 'vscode';

/**
 * 预览文件内容
 *
 * @author chitanda
 * @date 2022-01-18 14:01:48
 * @export
 * @class PreviewFile
 * @implements {FileStat}
 */
export class PreviewFile implements FileStat {
  type: FileType = FileType.File;
  ctime: number = Date.now();
  mtime: number = Date.now();
  size: number = 0;

  protected _content: string = '';
  protected _unit8content: Uint8Array = new Uint8Array(0);

  set content(content: string) {
    this._content = content;
    this._unit8content = Buffer.from(content);
    this.mtime = Date.now();
    this.size = this._unit8content.byteLength;
  }

  get content(): string {
    return this._content;
  }

  set unit8content(content: Uint8Array) {
    this._unit8content = content;
    this._content = content.toString();
    this.mtime = Date.now();
    this.size = this._unit8content.byteLength;
  }

  get unit8content(): Uint8Array {
    return this._unit8content;
  }
}
